<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>ES7 DEMO</title>
</head>
<body>

<button type="button" onclick="await()">await</button>
<button type="button" onclick="includes()">includes</button>
<button type="button" onclick="pow()">Math.pow()</button>
<button type="button" onclick="obj()">obj.key</button>
<button type="button" onclick="padStart()">padStart</button>


<script>
	//async await
	const sleep = time=>{
	    return new Promise(function (resolve, reject) {
	        setTimeout(function () {
	        	console.log('睡觉了...');
	            resolve();
	        }, time);
	    })
	};
	
	const await = async ()=>{
	    // 在这里使用起来就像同步代码那样直观
	    console.log('准备睡觉');
	    await sleep(1000);
	    await sleep(1000);
	    await sleep(1000);
	    console.log('睡了');
	};

	const includes=()=>{
		var arr=[{name:'cj'}, {name:'cbs'}, {name:'cxc'}]
		console.log(arr.includes({name:'cj'}));
		var arr2=[1, 2, 3]
		console.log(arr2.includes(3));
	}

	const pow=()=>{
		console.log(3**3);
		console.log(Math.pow(3,3)); //3的3次方
		console.log(Math.pow(3,4)); //3的4次方
	}
	const obj=()=>{

		let obj = {a: 1, b: 2, c: 3}
		console.log(JSON.stringify(Object.entries(obj)));

		let obj2 = {a: 1, b: 2, c: 3}
		for (let [key, value] of Object.entries(obj2)) {
		  	console.log(`${key} is ${value}`)
		}
	}

	const padStart=()=>{//填充字符串（显示用） 从左边开始填充20个字符
		console.log('react'.padStart(20).length)         // "       react" is 10
		console.log('react-native'.padStart(20).length)         // "  backbone" is 10
		console.log('0.00'.padStart(20))             
		console.log('10,000.00'.padStart(20))    
		console.log('250,000.00'.padStart(20))
		console.log('react'.padStart(20, '*'))         // "_____react"
		console.log('react-native'.padStart(20, '*'))         // "**backbone"
	}

</script>
	
</body>
</html>